/*
Realistic Unit Modification v4.0 Dialog 
v4.0.0.1 [ALPHA]
Concept & Development by Draper & Raps | [VRC]
*/

private ["_helo","_cRoF","_cFireRate","_array","_weaponclass","_pilot","_aimingQuality"];

/* sets variables used */
_array = _this select 3;
_helo = _array select 0;
_cRoF = _array select 1;
_weaponclass = _array select 3;
_cFireRate = 50;
_pilot = driver _helo;
_pilot sidechat "Firing canon!";
_grp = group _pilot;

/* forces the server side helo object to become client side. */
[_helo] joinSilent player;
[_helo] joinSilent grpNull;
[_helo] joinSilent _grp;
_helo setBehaviour "SAFE";
_helo setCombatMode "BLUE";

/* gathers the amount of ammo left and displays the information */
if (_helo ammo _weaponclass <= 200) then {
	_pilot sidechat format["Down to %1 rounds left!",_helo ammo _weaponclass];
} else {
	if (0 == _helo ammo _weaponclass) exitWith {
		_pilot sidechat "Winchester";
	};
};

/* checks to make sure that the laser designator is active */
if (isNull (laserTarget player)) exitWith {
	_pilot sideChat "Not able to Shoot, laser target lost";
};

/* main part of the script that fires the canon */
waitUntil {
	/* sets the rate of fire/wait cycle for how fast the canon fires */
	sleep _cRoF;
	
	/* how clean is the shot - more work to be done here... TODO */
	_aimingQuality = gunner _helo AimedAtTarget [(laserTarget player),_weaponclass];
	
	/* checks to make sure the player still has the laser pointed and turned on... */
	if (!isNull (laserTarget player)) then {
		/* verifies the hit chance */
		if (_aimingQuality > 0.5) then {
			_helo fireAtTarget [(laserTarget player),_weaponclass];
		};
	} else {
		_pilot sideChat "Not able to Shoot, no target";
	};
	_cFireRate = _cFireRate - 1;
	
	/* ends the waituntil loop when reached */
	_cFireRate <= 0;
};

/* exits the script */
if (true) exitWith {};